<?php

declare(strict_types=1);

namespace App\Command;

use App\Amqp\Producer\DemoProducer;
use function App\Helpers\getIpLocation;
use App\Helpers\StdArray;
use App\Service\QueueService;
use App\Task\FooTask;
use Hyperf\Amqp\Producer;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Command\Annotation\Command;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Utils\ApplicationContext;
use Psr\Container\ContainerInterface;
use Psr\SimpleCache\CacheInterface;
use Symfony\Component\Console\Input\InputArgument;
use Hyperf\AsyncQueue\Process\ConsumerProcess;
/**
 * @Command
 */
class FooCommand extends HyperfCommand
{
    /**
     * @var ContainerInterface
     */
    protected $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;

        parent::__construct('foo:hello');
    }

    public function configure()
    {
        parent::configure();

        $this->setHelp('Hyperf 自定义命令演示');
        $this->setDescription('Hyperf Demo Command');
        $this->addUsage('--name 演示代码');
    }



    /**
     * Notes:命令入口 都会执行这个方法
     * User: zba
     * Time: 2019/12/18 17:57
     */
    public function handle()
    {
        $arr = [
            ['key_1'=>'测试投递消息1'],
            ['key_2'=>'测试投递消息2'],
            ['key_3'=>'测试投递消息3'],
        ];
        // 从 $input 获取 name 参数
        //测试 amqp 投递消息
        $message = new DemoProducer($arr);
        $producer = ApplicationContext::getContainer()->get(Producer::class);
        $producer->produce($message);
//        var_dump('定时触发:'.date('Y-m-d H:i:s'));
//        var_dump(getIpLocation('110.179.228.16'));
        //测试缓存
//        var_dump(StdArray::indexed(['aa'=>1],null));
        //(new FooTask())->test();
//        $res = $this->container->get(CacheInterface::class)->set('name'.time(),['1234']);
//        $res = $this->container->get(CacheInterface::class)->delete('测试1');
        //测试多级缓存
//        $res = $this->container->get(CacheInterface::class)->setMultiple(['a11'=>1,'b22'=>2]);
//        $res = $this->container->get(CacheInterface::class)->getMultiple(['a11','b22']);

        $this->line('Hello 1info');
    }

    protected function getArguments()
    {
        return [
            ['name', InputArgument::OPTIONAL, '这里是对这个参数的解释'],
            ['name2', InputArgument::OPTIONAL, '这里是对这个参数的解释'],
        ];
    }


}
